package com.zaizai.controller;

import java.util.List;

import com.zaizai.domain.AjaxResult;
import com.zaizai.utils.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zaizai.domain.OrderCommdity;
import com.zaizai.service.IOrderCommdityService;

import static com.zaizai.domain.AjaxResult.success;

/**
 * 订单商品Controller
 *
 * @author zaiZai
 * @date 2024-10-23
 */
@RestController
@RequestMapping("/commdity")
public class OrderCommdityController extends BaseController {
    @Autowired
    private IOrderCommdityService orderCommdityService;

    /**
     * 查询订单商品列表
     */
    @GetMapping("/list")
    public TableDataInfo list(OrderCommdity orderCommdity) {
        startPage();
        System.out.println("orderCommdity = " + orderCommdity);
        List<OrderCommdity> list = orderCommdityService.selectOrderCommdityList(orderCommdity);
        return getDataTable(list);
    }

    /**
     * 获取订单商品详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(orderCommdityService.selectOrderCommdityById(id));
    }

    /**
     * 新增订单商品
     */
    @PostMapping
    public AjaxResult add(@RequestBody OrderCommdity orderCommdity) {
        return success(orderCommdityService.insertOrderCommdity(orderCommdity));
    }

    /**
     * 修改订单商品
     */

    @PutMapping
    public AjaxResult edit(@RequestBody OrderCommdity orderCommdity) {
        return success(orderCommdityService.updateOrderCommdity(orderCommdity));
    }

    /**
     * 删除订单商品
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return success(orderCommdityService.deleteOrderCommdityByIds(ids));
    }
}
